package com.zfk.framework.testcasepool;

import com.zfk.framework.case_loader.AllTestCaseLoader;
import com.zfk.framework.case_loader.YamlPathScanner;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.zfk.framework.models.CaseData;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestCaseInitializer {
    public static final Logger logger = LogManager.getLogger(TestCaseInitializer.class);
    //声明一个静态变量用例池，供其他类调用
    public static Map<String,CaseData> casePool = new HashMap<>();

    public static void initialize() {
        logger.info("开始初始化测试用例");
        try {
            //获取所有用例文件路径
            List<String> yamlFileList = YamlPathScanner.getAllCasePath();
            //加载用例
            casePool = AllTestCaseLoader.loaderTestCase(yamlFileList);
        } catch (IOException e) {
            logger.error("文件读取失败: {}", e.getMessage(), e);
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            logger.error("校验失败: {}", e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }
}
